<script setup lang="ts">
  import { ref } from 'vue';
  import { FormInstance, Message, TableInstance } from '@arco-design/web-vue';
  import useLoading from '@/hooks/loading';
  import {
    editbiangcompany,
    editzhizhicompany,
    getbaingcompanydetail,
    getzhihicompanydetail,
  } from '@/api/enterlibery';
  import { omit } from 'lodash';
  const formRef = ref<FormInstance | null>(null);
  const props = defineProps({
    visible: Boolean,
    params: Object,
  });
  const { loading, setLoading } = useLoading(false);
  const formType = ref();
  const formData = ref({});

  onMounted(() => {
    formType.value = [
      {
        name: 'change_item',
        label: '变更项目',
        type: 'a-input',
        fieldProps: {
          span: 24,
        },
        rules: [
          {
            required: true,
            message: '请输入',
          },
        ],
      },
      {
        name: 'change_before',
        label: '变更前',
        type: 'a-input',
        fieldProps: {
          span: 24,
        },
        rules: [
          {
            required: true,
            message: '请选择',
          },
        ],
      },
      {
        name: 'change_after',
        label: '变更后',
        type: 'a-input',
        fieldProps: {
          span: 24,
        },
        rules: [
          {
            required: true,
            message: '请输入',
          },
        ],
      },
      {
        name: 'change_date',
        label: '变更日期',
        type: 'a-date-picker',
        fieldProps: {
          span: 24,
          placeholder: '',
        },
        rules: [
          {
            required: true,
            message: '请选择',
          },
        ],
      },
    ];
    getbaingcompanydetail({
      change_id: props.params.changeid,
    }).then((res) => {
      formData.value = res.data;
    });
  });
  const emit = defineEmits(['update:visible', 'refresh']);
  const handleSubmit = async () => {
    if (!(await formRef.value?.checkForm())) {
      try {
        setLoading(true);
        const dataForm = formRef.value?.formModel;
        const res = await editbiangcompany({
          ...omit(dataForm, 'create_time', 'update_time', 'delete_time'),
          company_id: props.params.cid,
          change_id: props.params.changeid,
        });
        setLoading(false);
        Message.success(res.msg);
        emit('update:visible', false);
        emit('refresh');
      } catch (error) {
        // Message.error(error);
        setLoading(false);
      } finally {
        setLoading(false);
      }
    } else {
      Message.error('请正确填写表单！');
    }
  };
</script>

<template>
  <a-modal
    title="企业资质"
    :visible="visible"
    @ok="handleSubmit"
    title-align="start"
    :ok-loading="loading"
    width="55%"
    @cancel="
      () => {
        emit('update:visible', false);
      }
    "
  >
    <pro-form
      ref="formRef"
      hiddenBtn
      :form-json="formType"
      :form-data="formData"
    ></pro-form>
  </a-modal>
</template>

<style scoped lang="less">
  :deep(.arco-select-view-inner) {
    text-align: left !important;
  }
  .titile {
    margin-left: 12px;
    font-size: 13px;
    color: #4e5969;
  }
</style>
